<!DOCTYPE html>
<html lang='zh-CN'>
<head>
  <meta charset='utf-8'/>
  <meta http-equiv='X-UA-Compatible' content='IE=edge'/>
  <meta
    name='viewport'
    content='width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no'
  />
  <meta name='renderer' content='webkit'/>
  <title></title>
  <link rel='stylesheet' href='/public/admin/css/pintuer.css'/>
  <link rel='stylesheet' href='/public/admin/css/admin.css'/>
  <script src='https://cdn.bootcdn.net/ajax/libs/jquery/3.5.1/jquery.min.js'></script>
  <script src='/public/admin/js/pintuer.js'></script>
</head>
<body>
<div class='panel admin-panel'>
  <div class='panel-head'>
    <strong class='icon-reorder'>评论列表</strong>
    <a href='' style='float: right; display: none;'>添加字段</a>
  </div>
  <div class='padding border-bottom'></div>
  <table class='table table-hover text-center'>
    <% comment.forEach( item => { %>
    <tr>
      <th width='100' style='text-align: left; padding-left: 20px;'>ID</th>
      <th>用户名</th>
      <th>博客标题</th>
      <th>博客图片</th>
      <th>评论内容</th>
      <th>评论时间</th>
      <th>ip</th>
      <th>评论状态</th>
    </tr>
    <tr>
      <td><%= item.id %></td>
      <td><%= item.name %></td>
      <td><%= item.title %></td>
      <td>
        <a href='https://shixtao.cn/article/<%= item.blogId %>' target='_blank'>
          <img src='<%= item.img %>' width='200px'>
        </a>
      </td>
      <td><%= item.content%></td>
      <td><%= item.time%></td>
      <td><%= item.ip %></td>
      <td>
        <select onchange='status(this,<%= item.id %>,<%= item.blog_id %> )'>
          <option
          <%= +item.status === 0 ? 'selected' : '' %> value="0">未审核</option>
          <option
          <%= +item.status === 1 ? 'selected' : '' %> value="1">审核通过</option>
          <option
          <%= +item.status === 2 ? 'selected' : '' %> value="2">审核失败</option>
        </select>
      </td>
      <% reply.forEach(item2 => { %>
      <% if(item.id===item2.reply_id) { %>
    <tr>
      <th>回复id</th>
      <th>用户名</th>
      <th>评论内容</th>
      <th>评论时间</th>
      <th>评论状态</th>
    </tr>
    <tr>
      <td><%= item2.id %></td>
      <td><%= item2.name %></td>
      <td><%= item2.content %></td>
      <td><%= item2.time %></td>
      <td>
        <select onchange='status(this,<%= item2.id %>)' disabled>
          <option
          <%= +item2.status === 0 ? 'selected' : '' %> value="0">未审核</option>
          <option
          <%= +item2.status === 1 ? 'selected' : '' %> value="1">审核通过</option>
          <option
          <%= +item2.status === 2 ? 'selected' : '' %> value="2">审核失败</option>
        </select>
      </td>
    </tr>
    <% } %>
    <% }) %>
    </tr>
    <% }) %>
    <tr>
      <td colspan='8'>
        <div class='pagelist'>
          <%- show %>
        </div>
      </td>
    </tr>
  </table>
</div>
</body>
<script>
  function status(obj, id, blogId) {
    //接收状态值
    var statu = $(obj)
      .val();
    //发送ajax请求修改数据
    $.get('/admin/comment/ajax_status', { id: id, status: statu, blogId: blogId }, function(
      data,
    ) {
      if (data.success) {
        alert(data.message);
      } else {
        alert(data.message);
      }
    });
  }
</script>
</html>
